package com.lwk.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;
import java.util.List;

/**
 * swagger接口配置
 *
 * @author Administrator
 */
@Configuration
@EnableOpenApi
public class SwaggerConfig {

    /**
     * 是否开启swagger
     */
    //@Value("${swagger.enabled}")
    private boolean enabled = true;

    /**
     * 设置请求的统一前缀
     */
    @Value("${swagger.pathMapping}")
    private String pathMapping;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30)
                //是否启用swagger
                .enable(enabled)
                //从来创建API的基本信息，展示在文档的页面中（自定义展示的信息）
                .apiInfo(apiInfo())
                //设置哪些接口暴露给swagger展示设置
                .select()
                //扫描所有注解的api，用这种方式更灵活
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //.apis(RequestHandlerSelectors.basePackage("com.gsl"))
                //扫描所有.apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        //用ApiInfoBuilder进行定制
        return new ApiInfoBuilder()
                //设置标题
                .title("ES京东测试")
                //描述
                .description("李为康ES京东测试")
                //作者信息
                .contact(new Contact("lwk", null, "178440531@qq.com"))
                //版本号
                .version("版本号：1.0")
                .build();
    }
}

